﻿using System;
using System.Collections.Generic;
using FF14TreasureDiggingTool.ViewModels;
using Syncfusion.UI.Xaml.Grid;
using Wpf.Ui.Mvvm.Contracts;
using Wpf.Ui.Mvvm.Services;

namespace FF14TreasureDiggingTool.Views.Windows;

/// <summary>
/// Interaction logic for TaskManagerWindow.xaml
/// </summary>
public partial class TaskManagerWindow
{
    private readonly ISnackbarService _snackbarService;
    private readonly IDialogService _dialogService;
    public TaskManagerViewModel ViewModel { get; }

    public TaskManagerWindow(TaskManagerViewModel viewModel, ISnackbarService snackbarService, IDialogService dialogService)
    {
        _snackbarService = snackbarService;
        _dialogService = dialogService;
        ViewModel = viewModel;
        DataContext = this;
        InitializeComponent();
        _snackbarService.SetSnackbarControl(RootSnackbarT);
        _dialogService.SetDialogControl(RootDialogT);
        //gridRowResizingOptions.ExcludeColumns = excludeColumns;
        this.RecordsGrid.QueryRowHeight += RecordsGrid_QueryRowHeight;
    }

    GridRowSizingOptions gridRowResizingOptions = new GridRowSizingOptions();

    //To get the calculated height from GetAutoRowHeight method.    
    double autoHeight = double.NaN;
    // The list contains the column names that will excluded from the height calculation in GetAutoRowHeight method.
    //List<string> excludeColumns = new List<string>() { "RuleName", "DateRecord", "DeepestLayer" };


    void RecordsGrid_QueryRowHeight(object sender, QueryRowHeightEventArgs e)
    {
        if (this.RecordsGrid.GridColumnSizer.GetAutoRowHeight(e.RowIndex, gridRowResizingOptions, out autoHeight))
        {
            if (autoHeight > 24)
            {
                e.Height = autoHeight;
                e.Handled = true;
            }
        }
    }

    protected override void OnActivated(EventArgs e)
    {
        base.OnActivated(e);

        _dialogService.SetDialogControl(RootDialogT);
        _snackbarService.SetSnackbarControl(RootSnackbarT);
    }
}
